#!/usr/bin/perl -w
# 
# $Id: make-exp.pl,v 1.2 2003/09/11 07:09:17 srhea Exp $
#
use strict;

my $wanted = $ARGV[0];
my $seed = $ARGV[1];
my $graph = $ARGV[2];

my $count = 0;
my %stubs;

srand ($seed);

open (FILE, "$graph") or die "Could not open $graph\n";

while (<FILE>) {

    if (m/^(\d+)$/) {
        $count == 0 or die "More that one count?\n";
        $count = $1;
    }
    elsif (m/^(\d+) (\d+) (\d+) -1 -1$/) {
        # not a stub node
    }
    elsif (m/^(\d+) (\d+) (\d+) (\d+) (\d+)$/) {
        # a stub node
        $stubs{$1} = 1;
    }
    elsif (m/^(\d+) (\d+) (\d+)$/) {
        # an edge weight; we're done
        last;
    }
    else {
        die "Bad line: $_";
    }
}

close (FILE);

print "# Generated by make-exp.pl\n";
print "hosts\t\t192.168.0.1\n";
print "topology\t$graph\n";

for (my $i = 1; $i <= $wanted; ++$i) {
    my @k = keys %stubs;
    my $which = int rand ($#k + 1);
    if ($i == 1) {
        print "Gateway";
    }
    else {
        print "Node$i";
    }
    print "\tnode.cfg\tdynamic\tdaemon\t0\t$k[$which]\n";
    delete $stubs{$k[$which]};
}

